{% extends 'base_backend.html' %}
{% load static %}
{% block header_tail %}
    <link rel="stylesheet" href="{% static 'public/CodeMirror/lib/codemirror.css' %}">
    <link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
    <link rel="stylesheet" href="{% static 'public/CodeMirror/theme/lesser-dark.css' %}">
    <link rel="stylesheet" href="{% static 'public/CodeMirror/addon/dialog/dialog.css' %}">
    <link rel="stylesheet" href="{% static 'public/CodeMirror/addon/search/matchesonscrollbar.css' %}">
    <link rel="stylesheet" href="{% static 'plugins/select2/select2.css' %}">
    <link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/config/css/main.css' %}">
    <script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>
    <script src="{% static 'plugins/vue1/vue.js' %}"></script>

    <script src="{% static 'enjoyhint/js/enjoyhint.min.js' %}"></script>
    <link rel="stylesheet" href="{% static 'enjoyhint/css/enjoyhint.css' %}">
    <style>
        .login-banner {
            width: 100%;
            background: url("{% static 'public/img/banner2.jpg' %}") center bottom/cover no-repeat;
        }

        #second_pass {
            width: 30%;
            /*height: 30%;*/
            position: absolute;
            left: 50%;
            margin-left: -15%;
            top: 30%;
            z-index: 100;
            display: none;
            text-align: center;
            /*padding: 2%;*/
            border-radius: 10px;
            margin-bottom: 20px;
            border: 1px solid #A9C9E2;
            /*background-color: #E2EAF8;*/
        }

        .b1, .b2, .b3, .b4 {
            font-size: 1px;
            overflow: hidden;
            display: block;
        }

        .b1 {
            height: 1px;
            background: #AAA;
            margin: 0 5px;
        }

        .b2 {
            height: 1px;
            background: #E0E0E0;
            border-right: 2px solid #AAA;
            border-left: 2px solid #AAA;
            margin: 0 3px;
        }

        .b3 {
            height: 1px;
            background: #E3E3E3;
            border-right: 1px solid #AAA;
            border-left: 1px solid #AAA;
            margin: 0 2px;
        }

        .b4 {
            height: 2px;
            background: #E6E6E6;
            border-right: 1px solid #AAA;
            border-left: 1px solid #AAA;
            margin: 0 1px;
        }

        .contentb {
            background: #E9E9E9;
            border-right: 1px solid #AAA;
            border-left: 1px solid #AAA;
        }

        #second_pass p {
            margin: 6%;
        }

        #second_pass b {
            color: red;
            font-size: 20px;
        }

        #second_pass a {
            display: block;
            margin: 6%;
        }

        #second_pass span {
            margin-right: 10%
        }

        #second_pass h3 {
            margin-top: 6%;
        }
    </style>
{% endblock header_tail %}

{% block section_content %}

    <!--新手第二关-->
    <div id="second_pass" class="contentb">
        <b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
        <h3>恭喜你，完成了新手任务第二关</h3>
        <p>赏金 <b>＋5</b></p>
        <p style="margin-bottom: 30px">你太厉害了，相信你现在迫不及待的想进入实战吧!</p>
        <a href="{% url 'task:accept' %}">点我，去往任务市场领取任务吧！！！</a>
        <!--<p>-->
        <!--<span>实战任务-初级</span>-->
        <!--<a href="">前往任务</a>-->
        <!--<a href="">忽略此任务</a>-->
        <!--</p>-->
        <!--<p>-->
        <!--<span>实战任务-中级</span>-->
        <!--<a href="">前往任务</a>-->
        <!--<a href="">忽略此任务</a>-->
        <!--</p>-->
        <!--<p>-->
        <!--<span>实战任务-初级</span>-->
        <!--<a href="">前往任务</a>-->
        <!--<a href="">忽略此任务</a>-->
        <!--</p>-->
        <!--<p>-->
        <!--<span>实战任务-高级</span>-->
        <!--<a href="">前往任务</a>-->
        <!--<a href="">忽略此任务</a>-->
        <!--</p>-->
        <b class="b4"></b><b class="b3"></b><b class="b2"></b><b class="b1"></b>
    </div>
    <script>
        function second_pass_none() {
            var fist = $('#fist_pass');
            fist.css('display', 'none');
        }
    </script>

    <div>
        <div class="box-header with-border">
            <h3 class="box-title">{{ model_verbose_name }}</h3>
        </div>
        <!-- form start -->
        <div class="box box-primary">
            <div class="box-body">
                <input class="no-display" type="text">
                <p style="clear: both"></p>
                <div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">任务ID：</label>
                        <p id="taskId" type="text" class="config-input">{{ task.id }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">项目ID：</label>
                        <p type="text" class="config-input">{{ task.project_id }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">网站名称：</label>
                        <p type="text" class="config-input">{{ task.site_name }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">网站URL：</label>
                        <p type="text" class="config-input">{{ task.site_url }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">网站类型：</label>
                        <p type="text" class="config-input">{{ task.site_type }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">域名：</label>
                        <p type="text" class="config-input">{{ task.domain }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">一级域名：</label>
                        <p type="text" class="config-input">{{ task.first_domain }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">分配时间：</label>
                        <p type="text" id="allocation_flag" class="config-input"></p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">通过时间：</label>
                        <p id="finish_flag" type="text" class="config-input"></p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">分配代码：</label>
                        <p type="text" class="config-input">{{ task.process_type }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">任务备注：</label>
                        <p type="text" class="config-input">{{ task.note }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">录入时间：</label>
                        <p type="text" id="ctime" class="config-input"></p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">用户名：</label>
                        <p type="text" class="config-input">{{ task.user.username }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">网站国家：</label>
                        <p type="text" class="config-input">
                            {% if task.country %}
                                {{ task.country }}
                            {% else %}

                            {% endif %}
                        </p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">网站语言：</label>
                        <p type="text" class="config-input">{{ task.lang }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">任务描述：</label>
                        <p type="text" class="config-input">{{ task.description }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">任务状态：</label>
                        {% for filter in filters %}
                            {% if filter.status == task.status.code %}
                                <p type="text" id="status" class="config-input">{{ filter.name }}</p>
                            {% endif %}
                        {% endfor %}
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">ICP：</label>
                        <p type="text" class="config-input">{{ task.icp }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">管控平台任务描述：</label>
                        <p type="text" class="config-input">{{ task.gk_description }}</p>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="id" class="control-label">管控平台任务备注：</label>
                        <p type="text" class="config-input">{{ task.gk_remark }}</p>
                    </div>
                </div>
                <script>
                    var $a = jQuery.noConflict();
                    var $alloc = $a("#allocation_flag");
                    {% if task.allocation_flag == None %}
                        var alloc = null;
                    {% else %}
                        var alloc = {{ task.allocation_flag }};
                    {% endif %}
                    if (alloc) {
                        var newDate = new Date();
                        newDate.setTime(alloc * 1000);
                        $alloc.text(newDate.toLocaleDateString())
                    }

                    var $fin = $a("#finish_flag");
                    {% if task.finish_flag == None %}
                        var fin = null;
                    {% else %}
                        var fin = {{ task.finish_flag }};
                    {% endif %}
                    if (fin) {
                        var newDate = new Date();
                        newDate.setTime(fin * 1000);
                        $fin.text(newDate.toLocaleDateString())
                    }

                    var $ct = $a("#ctime");
                    {% if task.ctime == None %}
                        var ct = null;
                    {% else %}
                        var ct = {{ task.ctime }};
                    {% endif %}
                    if (ct) {
                        var newDate = new Date();
                        newDate.setTime(ct * 1000);
                        $ct.text(newDate.toLocaleDateString())
                    }
                </script>
                <br style="clear: both">
                <hr style="margin-top: 0">
                <div class="form-group">
                    <div style="float: left;" class="input-group select-config-div">
                        <label for="">配置列表：</label>
                    </div>
                    <div style="float: left;" class="input-group select-config-div">
                        {% if task.status.code == 2 or task.status.code == 5 or task.status.code == 10 %}
                            {% if task.is_affirm == 1 %}
                                <a href="{% url 'task:add_config' %}?tid={{ task.id }}" class="btn btn-info btn-xs"
                                   tag="1"
                                   id="config-add">添加配置</a>
                            {% endif %}
                        {% endif %}
                    </div>
                    <div style="float: left; color: red;">
                        <span id="message"></span>
                    </div>
                    <span style="color: #00a7d0;margin-left: 10px"></span>
                </div>

                <div class="form-group" id="configList">
                    <table id="config_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th v-for="head in headers">
                                <span style="float: left">
                                    [[ head.name ]]
                                </span>
                            </th>
                            <th>
                                <span style="float: left">
                                    操作
                                </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <template v-for="config in configs">
                            <!--<tr v-if="task.allocation_flag">-->
                            <tr>
                                <template v-for="head in headers">
                                    <td v-if="head.key == 'allocation_flag' || head.key == 'ctime' || head.key == 'finish_flag'">
                                        [[ parseTime(config[head.key]) ]]
                                    </td>
                                    <td v-else>[[ config[head.key] ]]</td>
                                </template>
                                <!--<td v-for="head in headers">[[ config[head.key] ]]</td>-->
                                <td class="btn-group">

                                        <button v-if="config._status == 2 || config._status == 5" type="button"
                                                value="[[ config.id ]]" class="btn btn-info btn-xs"
                                                onclick="deleteOneConfig([[ config.id ]])">删除
                                        </button>
                                        <button type="button" value="[[ config.id ]]" class="btn btn-info btn-xs"
                                                onclick="detailOneConfig([[ config.id ]])">详情
                                        </button>


                                </td>
                            </tr>
                        </template>
                        </tbody>
                    </table>
                </div>
                <div>
                    {% if task.status.code == 1 %}
                        <p id="hint-get-task" class="btn btn-primary" onclick="accept({{ task.id }})">领取任务</p>
                        {% if not new_tasks %}
                            <script src="{% static 'enjoyhint/js/hint-sequence-2.js' %}"></script>
                            <!--页面停留时间-->
                            <script>
                                if (getCookie('NewbieSkip') !== '1') {
                                    var start, stop, step = 6;

                                    function dt() {
                                        var date = new Date();
                                        return date.getTime();
                                    }

                                    window.onload = function () {
                                        start = dt();
                                    };
                                    window.onbeforeunload = function () {
                                        stop = dt();
                                        tp = stop - start;
                                        $.post({
                                            data: {
                                                csrfmiddlewaretoken: '{{ csrf_token }}',
                                                step: step,
                                                tp: tp,
                                                last_event: '',
                                                next_event: '',
                                                behavior_weight: '新手引导'
                                            },
                                            url: "{% url 'zhongbao_admin:behavior_record' %}"
                                        });
                                        start = stop;
                                    };
                                }
                                ;
                            </script>
                        {% endif %}
                    {% elif task.status.code == 2 or task.status.code == 10 %}
                        <p id="hint-put-check" class="btn btn-primary" onclick="audit({{ task.id }})">提交审核</p>
                        <p id="apple-recovery" class="btn btn-primary" onclick="recovery({{ task.id }})">申请回收</p>
                        <p id="task-test-config" class="btn btn-primary" onclick="test_config({{ task.id }})">测试配置</p>
                        {#                    {% elif task.status.code == 5 and qq %}#}
                        {#                        <p id="hint-put-check" class="btn btn-primary" onclick="audit({{ task.id }})">提交审核</p>#}
                        {#                        <p class="btn btn-primary" onclick="alarms_fail({{ task.id }})">申请重审</p>#}
                        {#                        <p id="task-test-config" class="btn btn-primary" onclick="test_config({{ task.id }})">测试配置</p>#}
                        {#                        <div style="margin-top:20px;">#}
                        {#                            {% if disqualify_reason_new %}#}
                        {#                                <b>不合格原因:{{ disqualify_reason_new }}#}
                        {#                                    补充描述:{{ task.disqualify_reason }}</b>&nbsp&nbsp<b>审核人:{{ username }}</b>#}
                        {#                                <a target="_blank"#}
                        {#                                   href="http://wpa.qq.com/msgrd?v=3&uin={{ qq }}&site=qq&menu=yes"><img#}
                        {#                                        border="0" src="http://wpa.qq.com/pa?p=2:{{ qq }}:51" alt="点击这里给我发消息"#}
                        {#                                        title="点击这里给我发消息"/></a>#}
                        {#                            {% else %}#}
                        {#                                <b>不合格原因:{{ task.unfeedback }}</b>#}
                        {#                            {% endif %}#}
                        {#                        </div>#}
                    {% elif task.status.code == 5 %}
                        {% if task.is_affirm == 1 %}
                            <p id="hint-put-check" class="btn btn-primary" onclick="audit({{ task.id }})">提交审核</p>
                        {% endif %}

                        <!--                    <p class="btn btn-primary" data-toggle="modal" data-target="#WhiteListMessage">误判</p>-->
                        {% if task.is_affirm == 0 %}
                            <p class="btn btn-primary" onclick="alarms_fail({{ task.id }})">申请重审</p>
                            <p class="btn btn-primary" onclick="task_affirm({{ task.id }})">确认不合格</p>
                        {% endif %}
                        {% if task.is_affirm == 1 %}
                            <p id="task-test-config" class="btn btn-primary" onclick="test_config({{ task.id }})">
                                测试配置</p>
                        {% endif %}
                        <div style="margin-top:20px;">

                            {% if disqualify_reason_new %}
                                <br><b>不合格原因:{{ task.disqualify_reason_new }} 补充描述:{{ task.disqualify_reason }}</b>
                            {% else %}
                                <b>不合格原因:{{ task.unfeedback }}</b>
                            {% endif %}
                        </div>
                    {% elif task.status.code == 3 %}
                        <p id="task-test-config" class="btn btn-primary" onclick="test_config({{ task.id }})">
                            测试配置</p>
                    {% elif task.is_rework == 1 %}
                        <p class="btn btn-primary" data-toggle="modal" data-target="#reworkMessage">修改完成/反馈</p>
                    {% endif %}

                </div>

                <br>
            </div>
        </div>
    </div>

    <!--  审核记录   -->
    <div class="row">
        <div class="col-md-6">
            <!-- DIRECT CHAT -->
            <div class="box box-primary direct-chat direct-chat-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">审核记录</h3>
                    <div class="box-tools pull-right">
                        <span data-toggle="tooltip" title="{{ communicatesNum }} Messages"
                              class="badge bg-blue">{{ communicatesNum }}</span>
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
                                class="fa fa-minus"></i>
                        </button>
                    </div>
                </div>
                <div class="box-body">
                    <table id="auditRecordTable" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th class="action-checkbox">
                                    <span style="float: left">
                                        审核时间
                                    </span>
                            </th>
                            <th>
                                    <span style="float: left">
                                        变更前
                                    </span>
                            </th>
                            <th>
                                    <span style="float: left">
                                        变更后
                                    </span>
                            </th>
                            <th style="width: 350px;">
                                    <span style="float: left">
                                        不合格原因
                                    </span>
                            </th>
                            <th>
                                    <span style="float: left">
                                        审核人员
                                    </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-if="auditRecord == '' ">
                            <td>暂无记录</td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                        <template v-for="record in auditRecord">
                            <tr>
                                <td>
                                    <span>[[ parseTime(record.changed_flag) ]]</span>
                                </td>
                                <td>
                                    <span>[[ record.changed_before ]]</span>
                                </td>
                                <td>
                                    <span>[[ record.changed_after ]]</span>
                                </td>
                                <td>
                                    <span>[[ record.unfeedback ]]</span>
                                </td>
                                <td>
                                    <span>[[ record.auditor ]]</span>
                                </td>
                            </tr>
                        </template>
                        </tbody>
                    </table>
                </div>

                <div class="box-footer">
                    <div class="input-group">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--确认删除配置弹出框-->
    <div class="modal fade" id="delete-config-window" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:30%">
        <div class="modal-dialog" role="document">
            <div class="panel panel-danger">
                <div class="panel-heading">
                    <h3 class="panel-title">确认要删除配置吗？</h3>
                </div>
                <div class="modal-footer">
                    <button type="button" id="cancel_delete" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                    <span id="submit-delete" class="btn btn-default" onclick="deleteConfigs()">
                        确定
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!--修改完成/反馈-->
    <div class="modal fade" id="reworkMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>如无误请填写反馈结果：</label>
                </div>
                <div id="reworkBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    <input style="width:400px;height:100px;" type="text" id="rework_message" name="rework_message"/>
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="rework_done('{{ task.id }}')"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="operationMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请选择取消原因（若无故申请取消会扣除经验哦！）</label>
                </div>

                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    <table id="operation_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <tbody>
                        <tr>
                            <td class="action-checkbox">
                                <input type="radio" name="utd_checkbox" value="网站失效" onclick="_checkOne(this)">
                            </td>
                            <td>网站失效，无法打开</td>
                        </tr>
                        <tr>
                            <td class="action-checkbox">
                                <input type="radio" name="utd_checkbox" value="网页无法抓取" onclick="_checkOne(this)">
                            </td>
                            <td>网页无法抓取</td>
                        </tr>
                        <tr>
                            <td class="action-checkbox">
                                <input type="radio" name="utd_checkbox" value="网页无更新" onclick="_checkOne(this)">
                            </td>
                            <td>网页无更新</td>
                        </tr>
                        其他原因
                        <textarea name="information" style="width: 80%; height: 20%" placeholder="请输入其他原因"></textarea>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="submission()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="WhiteListMessage" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="whiteBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要提交误报吗？如被审为非法提交误报该任务将被直接回收！
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="add_white_list()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="taskMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    请至少选择一个状态，或说明状态！
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">确认
                    </button>
                </div>
            </div>
        </div>
    </div>
    <input id="taskIds" value="" style="display:none;"></input>
    <!--提示消息--end-->
    <div class="modal fade" id="operationMessage1" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请输入申请"误审"的原因：</label>
                </div>

                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">

                    <input style="width:400px;height:100px;" type="text" id="fankui" name="fankuiyy"/>

                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="distort_audit()"
                            data-dismiss="modal">确认
                    </button>

                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <script>
        function setCookie(key, value, t) {
            var oDate = new Date();
            oDate.setDate(oDate.getDate() + t);
            document.cookie = key + "=" + value + "; expires=" + oDate.toDateString();
        }

        function getCookie(key) {
            var arr1 = document.cookie.split("; ");
            for (var i = 0; i < arr1.length; i++) {
                var arr2 = arr1[i].split("=");
                if (arr2[0] == key) {
                    return decodeURI(arr2[1]);
                }
            }
        }

        //封装一个移除cookie的函数
        function removeCookie(key) {
            setCookie(key, "", -1);//把cookie设置为过期
        }
    </script>
    {% if not new_tasks %}
        <script>
            if (getCookie('NewbieSkip') !== '1') {
                // 新手任务
                document.getElementById("config-add").href = 'javascript:void(0);';
                var enjoyhint_instance = new EnjoyHint({
                    onEnd: function () {
                        $('#second_pass').css('display', 'block');
                        $.post({
                            data: {
                                csrfmiddlewaretoken: '{{ csrf_token }}',
                                award_subtype: '2'
                            },
                            url: "{% url 'task:newbie_task' %}"
                        });
                    }
                });

                var enjoyhint_script_steps = [
                    {
                        'next #config-add': '在这里上传配置！',
                        'nextButton': {className: "myNext", text: "下一步"},
                        'skipButton': {className: "mySkip", text: "跳过"}
                    },
                    {
                        'next #hint-put-check': '点击提交审核后就可以静待赏金！',
                        'shape': 'circle',
                        'radius': 70,
                        'showSkip': false,
                        'nextButton': {className: "myNext", text: "完成"}
                    }
                ];

                enjoyhint_instance.set(enjoyhint_script_steps);
                enjoyhint_instance.run();
                //    页面停留时间
                var $step = jQuery.noConflict();
                var start, stop, step = 7;

                function dt() {
                    var date = new Date();
                    return date.getTime();
                }

                window.onload = function () {
                    start = dt();
                };
                $step(".enjoyhint_next_btn").click(function () {
                    stop = dt();
                    tp = stop - start;
                    $.post({
                        data: {
                            csrfmiddlewaretoken: '{{ csrf_token }}',
                            step: step,
                            tp: tp,
                            last_event: '',
                            next_event: '',
                            behavior_weight: '新手引导'
                        },
                        url: "{% url 'zhongbao_admin:behavior_record' %}"
                    });
                    step++;
                    start = stop
                })
            }
        </script>
    {% endif %}
    <script>
        var $b = jQuery.noConflict();
        Vue.config.delimiters = ["[[", "]]"];

        var _cids;

        function deleteOneConfig(cid) {
            //$("#configIds").val(cid);
            _cids = cid;
            $("#delete-config-window").modal();
        }

        function deleteConfigs(cids) {
            if (!cids) {
                cids = _cids
            }
            if (!cids) {
                alert("请给出要删除的配置ID！")
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        cids: cids
                    }
                });
                $.post(
                    "{% url 'task:delete_config' %}",
                    function (response) {
                        if (response.message) {
                            alert(response.message);
                        }
                        window.location.reload();
                        _cids = null;
                    }
                )
            }
        }

        function detailOneConfig(cid) {
            var url = "{% url 'task:detail' %}" + "?id=" + cid + "&type=config";
            window.location.href = url;
        }

        function toPage(response, page, url) {
            var sec = 2000;
            var message = response.message;
            var result = response.result;
            var $message = $("#message");
            if (message) {
                $message.text(message);
            }
            setTimeout(function () {
                console.log(url);
                if (url) {
                    window.location.href = url;
                } else {
                    if (page == -1) {
                        window.location.href = document.referrer;
                    } else {
                        if (result === true) {
                            window.location.href = "";
                        } else {
                            $message.text(message);
                        }
                    }
                }
            }, sec);
        }

        function accept(tids) {
            if (!tids) {
                return false
            }
            if (tids.length === 0) {
                return false
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids,
                        cvalue: '领取'
                    }
                });
                $.post(
                    "{% url 'task:accept' %}",
                    function (response) {
                        //console.log(response);
                        toPage(response);
                    }
                )
            }
        }

        function retrieve(tids) {
            if (!tids) {
                return false
            }
            if (tids.length === 0) {
                return false
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids
                    }
                });
                $.post(
                    "{% url 'task:retrieve' %}",
                    function (response) {
                        toPage(response, -1)
                    }
                )
            }
        }

        function audit(tids) {
            if (configListVue.configs.length == 0) {
                var response = {result: false, message: "您是否已添加了配置？如果已经添加，请刷新本页后重试。"};
                toPage(response);
                return false
            }
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    id: tids,
                }
            });
            {% if task.status.code == 2 or task.status.code == 10 %}
                $.post(
                    "{% url 'task:audit' %}",
                    function (response) {
                        console.log(response);
                        //window.history.back(-1);
                        //var url = "{/% url 'task:handle' %}";
                        //console.log(url);
                        toPage(response)
                    }
                );
            {% elif task.status.code == 5 %}
                $.post(
                    "{% url 'task:re_audit' %}",
                    function (response) {
                        console.log(response);
                        toPage(response)
                    }
                );
            {% endif %}

        }

        function distort_audit() {
            var tids = $("#taskIds").val();
            var fankui = $("#fankui").val();

            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    id: tids,
                    reason: fankui
                }
            });

            $.post(
                "{% url 'task:distort_re_audit' %}",
                function (response) {
                    console.log(response);
                    toPage(response)
                }
            );
        }

        function reject() {
            var id = {{ task.id }};
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    id: id
                }
            });
            $.post(
                "{% url 'task:reject' %}",
                function (response) {
                    //console.log(response);
                    toPage(response, -1);
                }
            )
        }

        function pass() {
            var tid = {{ task.id }};
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tid: tid
                }
            });
            $.post(
                "{% url 'task:pass' %}",
                function (response) {
                    //console.log(response);
                    toPage(response, -1)
                }
            )
        }

        var configListVue = new Vue({
            el: "#configList",
            data: {
                headers: [],
                configs: [],
                message: ""
            },
            methods: {
                parseTime: function (timeStamp) {
                    if (!timeStamp) {
                        return ""
                    }
                    var newDate = new Date();
                    newDate.setTime(timeStamp * 1000);
                    return newDate.toLocaleDateString()
                }
            }
        });

        function getConfigs(obj) {
            var formData = "tid={{ task.id }}";
            $b.get(
                "{% url 'task:get_configs' %}",
                formData,
                function (response) {
                    if (response) {
                        obj.headers = response.headers;
                        obj.configs = response.configs;
                        obj.message = response.message;
                        //console.log(obj.configs)
                    } else {
                        obj.message = "无法获取到配置信息。";
                    }
                }
            )
        }

        getConfigs(configListVue);
        $b("#myTasks").addClass("active");

        // 新手任务跳过
        $b('.enjoyhint_skip_btn').click(function () {
            // document.getElementById("config-add").href="{% url 'task:add_config' %}?tid={{ task.id }}";
            setCookie('NewbieSkip', '1', 365);
            alert('您可以前往我的任务/项目--奖励任务模块，查看完成新手任务哦~');
        });

        function recovery(taskid) {
            if (!taskid) {
                alert('当前任务获取失败，请刷新重试！')
            } else {
                $("#operationMessage").modal();
            }
        }

        function test_config(tid) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tid
                }
            });
            $.post(
                "{% url 'task:task_test_config' %}",
                function (response) {
                    //console.log(response);
                    {#toPage(response, -1)#}
                    var sec = 2000;
                    var message = response.message;
                    var result = response.result;
                    var $message = $("#message");
                    if (message) {
                        $message.text(message);
                    }
                }
            )
        }

        function _checkOne(obj) {
            if ($b("input[name='uth_checkbox']").is(":checked")) {
                $b("input[name='uth_checkbox']").prop("checked", false)
            } else {
                var unChecked = 0;
                $b("input[name='utd_checkbox']").each(
                    function () {
                        if ($b(this).is(":checked")) {

                        } else {
                            unChecked += 1
                        }
                    }
                );
                if (unChecked === 0) {
                    $b("input[name='uth_checkbox']").prop("checked", true)
                }
            }
        }

        function submission() {
            var tid =
            {{ task.id }}
            var cvalue = ''
            var information = ''
            var information = $("textarea[name='information']").val()
            $b("input[name='utd_checkbox']:checked").each(
                function () {
                    cvalue = $b(this).val();
                }
            );
            console.log(cvalue)
            if (cvalue === '' && information === '') {
                $("#taskMessage").modal();
                return false;
            } else if (information) {
                opera(tid, information)
            } else {
                console.log(cvalue)
                console.log(information)
                opera(tid, cvalue);
            }
        }

        function opera(tids, cvalue) {
            if (!tids) {
                var _tids = [];
                $b("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($b(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                return false
            } else {
                $.ajax({
                    type: "POST",
                    url: "{% url 'task:recovery' %}",
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids,
                        cvalue: cvalue
                    },
                    success: function (data) {
                        alert(data.message);
                        if (data.message === '申请成功,管理人员将会核实!') {
                            var url = "{% url 'task:mine' %}" + "?status=2";
                            window.open(url);
                        }
                    }
                })
            }
        }

        // 修改完成
        function rework_done(task_id) {
            var rework_result = $('#rework_message').val();
            $.post({
                url: "{% url 'task:rework_done' %}",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    task_id: task_id,
                    rework_result: rework_result
                },
                success: function (data) {
                    alert(data.message);
                    window.location.reload();
                }
            })
        }

        // 添加白名单
        function add_white_list() {
            var task_id = '{{ task.id }}';
            $.post({
                url: "{% url 'task:add_white_list' %}",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    task_id: task_id
                },
                success: function (data) {
                    alert(data.message);
                    window.location.reload();
                }
            })
        }

        var auditRecordVue = new Vue({
            el: "#auditRecordTable",
            data: {
                searchForm: "",
                auditRecord: {},
            },
            methods: {
                parseTime: function (timeStamp) {
                    if (!timeStamp) {
                        return ""
                    }
                    var newDate = new Date();
                    newDate.setTime(timeStamp * 1000);
                    return newDate.toLocaleDateString()
                },
            }
        });


        // 审核记录
        function auditRecord() {
            var searchForm = 'tid=' + '{{ task.id }}';
            $b.get(
                "{% url 'task:task_audit_record_detail' %}",
                searchForm,
                function (response) {
                    if (response) {
                        console.log(response.data);
                        auditRecordVue.auditRecord = response.data;
                    }
                }
            );
        };

        function alarms_fail(tids) {
            if (tids) {
                $("#taskIds").val(tids);
                $("#operationMessage1").modal();
            } else {
                return false
            }
        }


        function task_affirm(tid) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tid
                }
            });
            $.post(
                "{% url 'task:task_affirm' %}",
                function (response) {
                    //console.log(response);
                    {#toPage(response, -1)#}
                    var sec = 2000;
                    var message = response.message;
                    var result = response.result;
                    var $message = $("#message");
                    if (message) {
                        $message.text(message);
                    }
                    window.location.reload();
                }
            )
        }

    </script>

{% endblock section_content %}